% radar_signal.m
% 
% Outputs two cosine waves with a phase delay from the input wave
% determined by the distance of the antennas and the random x and y
% positions of the object   
% 
% Outputs: Received wave at antenna 1, Received wave at antenna 2
% Inputs: Sent Cosine wave, position Antenna 1, position Antenna 1,
% frequency of sent wave, velocity of wave, sample rate used on Cosine wave
% 
% Authors: Chris Chester, Nathan Rich
% Date: 7/08/2011


function [wave1,wave2,time1,time2] = radar_signal(sent_wave,a1pos,a2pos,freqwave,velowave,srate)

    n = length(sent_wave);
    atten_rate = 1; % signal loses half its power each kilometer
    wave1 = zeros(n,1);  %initialising Output 
    wave2 = zeros(n,1); 
    
    x= 5; %Randomise Placement of object in km
    y= 8;
    
    dis_a1 = sqrt((x - a1pos)^2 + (y - 0)^2); %distance from object to antenna 1
    del_a1 = 2*dis_a1/velowave; % Time the wave has been delayed by
    phase_delay1 = mod(del_a1*freqwave*2*pi,2*pi); %Phase delay in a1 to object and back, *2 to get there and back

    dis_a2 = sqrt((x - a2pos)^2 + (y - 0)^2);
    del_a2 = 2*dis_a2/velowave;  %in seconds
    phase_delay2 = mod(del_a2*freqwave*2*pi,2*pi); % in rad
    
    %adding attenuation to each signal
    atten_a1 =  atten_rate^dis_a1; 
    atten_a2 =  atten_rate^dis_a2;
    
    
    
    for I = 1:n % creating recieved signals
        noise = ((-1)^randi(2))*rand()/6;

        wave1(I) = noise + cos((I*2*pi/srate - phase_delay1))* atten_a1;
        wave2(I) = noise + cos((I*2*pi/srate - phase_delay2))* atten_a2;
            
    end
    
    wave1 = wave1;
    wave2 = wave2;
    time1 = del_a1;
    time2 = del_a2;
    
end
    
    
    
